package com.itheima.tlias08_14.controller;


import com.itheima.tlias08_14.entity.TestClazz;
import com.itheima.tlias08_14.utils.ResultUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class TestApplicationContextController {


    @Autowired
    @Resource
    ApplicationContext context;

    @Resource( name = "testClazz")
    TestClazz testClazz;

    @GetMapping("bean")
    public ResultUtil getBean(){
        log.info("resource getByName TestClazz = {}",testClazz);
        //通过类型获取目标bean对象
        log.info("Context get TestClazz = {}",context.getBean(TestClazz.class));
        //通过名称获取目标bean对象
        log.info("Context get TestClazz = {}",context.getBean("clazz"));

        return ResultUtil.success(testClazz);
    }

}
